package com.cqw.jackson;

import com.cqw.utils.AESUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: caoqingwen
 * @CreateTime: 2021-08-25 15:01
 * @Description: id自定义序列化
 */
@Component
public class IdSerializer extends JsonSerializer<Long> {


    /**
     * 序列化id
     *
     * @param value
     * @param gen
     * @param serializers
     * @throws IOException
     */
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (value == null) {
            return;
        }

        String valueStr = AESUtil.encrypt(value.toString(), "q1");
        gen.writeString(valueStr);
    }
}
